package com.lzq.leetcode.hoot100;

import com.lzq.leetcode.hoot100.ds.TreeNode;

import java.util.LinkedList;
import java.util.Queue;

public class s104 {

    public int maxDepth(TreeNode root) {
        // 广度
        Queue<TreeNode> queue = new LinkedList<>();
        if (root != null)   queue.offer(root);
        int ans = 0;
        while (!queue.isEmpty()) {
            // 取出元素
            for (int i=0; i<queue.size(); i++) {
                TreeNode poll = queue.poll();
                if (poll.left != null)  queue.offer(poll.left);
                if (poll.right != null) queue.offer((poll.right));
            }
            ++ans;
        }

        return ans;
    }

}
